package com.bl.weilan.service.biz.informationType.impl;

import com.bl.weilan.common.utils.UUIDUtils;
import com.bl.weilan.dao.model.InformationTypeEntity;
import com.bl.weilan.dao.repository.InformationTypeRepository;
import com.bl.weilan.service.biz.informationType.InformationTypeService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.informationtype.InformationTypeListVo;
import com.bl.weilan.service.vo.informationtype.InformationTypeVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
@Log4j2
public class InformationTypeServiceImlp implements InformationTypeService {
    @Autowired
    InformationTypeRepository informationTypeRepository;

    @Override
    public InformationTypeListVo getInformationTypeList(Pageable pageable){
        Page<InformationTypeEntity> informationTypeEntities;
        InformationTypeListVo informationTypeListVo = new InformationTypeListVo();

        informationTypeEntities = informationTypeRepository.findAll(pageable);

        informationTypeListVo.setTotalCount(informationTypeEntities.getTotalElements());
        informationTypeListVo.setList(informationTypeEntities.getContent());

        return informationTypeListVo;
    }

    @Override
    public void add(InformationTypeVo informationTypeVo) {

        InformationTypeEntity informationTypeEntity = new InformationTypeEntity();

        informationTypeEntity.setId(UUIDUtils.getUUID());
        BeanUtils.copyProperties(informationTypeVo, informationTypeEntity);

        informationTypeRepository.save(informationTypeEntity);
    }

    @Override
    public void del(DelBody id) {

        informationTypeRepository.delete(id.getId());

    }


}
